
export const format = (t, type) => {
	var time = new Date(t);
	var y = time.getFullYear();
	var m = time.getMonth()+1;
	var d = time.getDate();
	var h = time.getHours();
	var mm = time.getMinutes();
	var s = time.getSeconds();
	let add0 = m => {
		return m<10?'0'+m:m
	}
	if (type === 'YMD') {
		return y+'-'+add0(m)+'-'+add0(d);
	} else {
		return y+'-'+add0(m)+'-'+add0(d)+' '+add0(h)+':'+add0(mm)+':'+add0(s);
	}
	
}
export const FunGetDateStr = (p_count) => {
	var dd = new Date();
	dd.setDate(dd.getDate() + p_count);//获取p_count天后的日期
	var y = dd.getFullYear();
	var m = dd.getMonth() + 1;//获取当前月份的日期
	if( m <10){
			m = '0'+m;
	}
	var d = dd.getDate();
	if( d <10){
			d = '0'+d;
	}
	return y + "-" + m + "-" + d;
}
 /*
	* 获取之前月份
  * 
  * @date 格式为yyyy-mm-dd的日期，如：2014-01-25 
  */  
export const getPreMonth = (monthNum) => {
	var date = new Date()
	var year = date.getFullYear(); //获取当前日期的年份  
	var month = date.getMonth()+1; //获取当前日期的月份  
	var day = date.getDate(); //获取当前日期的日  
	var days = new Date(year, month, 0);  
	days = days.getDate(); //获取当前日期中月的天数  
	var year2 = year;  
	var month2 = parseInt(month) - monthNum;
	var day2 = day; 
	if (month2 <= 0) {  
			year2 = parseInt(year2) - 1;  
			month2 = 12;
	}  
	 
	var days2 = new Date(year2, month2, 0);  
	days2 = days2.getDate();  
	if (day2 > days2) {  
			day2 = days2;  
	}  
	if (month2 < 10) {  
			month2 = '0' + month2;  
	}
	if (day2 < 10) {
		day2 = '0' + day2;  
	}
	var t2 = year2 + '-' + month2 + '-' + day2;  
	return t2;  
}